/*
 ============================================================================
 Name		: RtWeiboAppView.cpp
 Author	  : hou maoqing
 Copyright   : Your copyright notice
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "RtWeiboAppView.h"
#include "RtWeiboAppUi.h"
#include "RtKeyDefine.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CRtWeiboAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CRtWeiboAppView* CRtWeiboAppView::NewL(const TRect& aRect)
	{
	CRtWeiboAppView* self = CRtWeiboAppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CRtWeiboAppView* CRtWeiboAppView::NewLC(const TRect& aRect)
	{
	CRtWeiboAppView* self = new (ELeave) CRtWeiboAppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CRtWeiboAppView::ConstructL(const TRect& aRect)
	{
	// Create a window for this application view
	CreateWindowL();

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::CRtWeiboAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CRtWeiboAppView::CRtWeiboAppView()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::~CRtWeiboAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CRtWeiboAppView::~CRtWeiboAppView()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CRtWeiboAppView::Draw(const TRect& aRect) const
	{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();
	
	CRtWeiboAppUi* pAppUi=(CRtWeiboAppUi*)CEikonEnv::Static()->AppUi();
	CRtWindowGc rtGc(&gc);
	CRtRect rtRect(aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY);
	pAppUi->m_pRtWeiboApp->UiDraw(rtGc,rtRect);

	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CRtWeiboAppView::SizeChanged()
	{
	DrawNow();
	}

// -----------------------------------------------------------------------------
// CRtWeiboAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CRtWeiboAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
	{
	TRtPointerEvent ptEvent;
	ptEvent.uiType=aPointerEvent.iType;
	ptEvent.iPosition.m_nX=aPointerEvent.iPosition.iX;
	ptEvent.iPosition.m_nY=aPointerEvent.iPosition.iY;
	
	CRtWeiboAppUi* pAppUi=(CRtWeiboAppUi*)CEikonEnv::Static()->AppUi();
	if(pAppUi->m_pRtWeiboApp)
		return pAppUi->m_pRtWeiboApp->HandlePointerEventL(ptEvent);
	
	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
	}

TInt CRtWeiboAppView::CountComponentControls() const
	{
	CRtWeiboAppUi* pAppUi=(CRtWeiboAppUi*)CEikonEnv::Static()->AppUi();
	if(pAppUi->m_pRtWeiboApp)
		return pAppUi->m_pRtWeiboApp->CountComponentControls();
	else
		return 0;
	}
				
CCoeControl* CRtWeiboAppView::ComponentControl( TInt aIndex ) const
	{
	CRtWeiboAppUi* pAppUi=(CRtWeiboAppUi*)CEikonEnv::Static()->AppUi();
	if(pAppUi->m_pRtWeiboApp)
		return (CCoeControl*)pAppUi->m_pRtWeiboApp->ComponentControl(aIndex);
	else
		return NULL;
	}

TKeyResponse CRtWeiboAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	CRtWeiboAppUi* pAppUi=(CRtWeiboAppUi*)CEikonEnv::Static()->AppUi();
	
	TRtKeyEvent keyEvent;
	keyEvent.iCode=aKeyEvent.iCode;
	keyEvent.iScanCode=aKeyEvent.iScanCode;
	keyEvent.iRepeats=aKeyEvent.iRepeats;
	keyEvent.iModifiers=aKeyEvent.iModifiers;
	
	if(keyEvent.iScanCode==167)
		keyEvent.iCode=ERtKeyOk;
	
	TRtKeyEventType eventType=(TRtKeyEventType)aType;
	bool r=pAppUi->m_pRtWeiboApp->HandleKeyEvent(keyEvent,eventType);
	if(r)
		return EKeyWasConsumed;
	else
		CCoeControl::OfferKeyEventL(aKeyEvent,aType);
	}

// End of File
